package com.yonder.testjvmmemory;

public class Main {
	
	static boolean[] arr1 = null;
	static byte[] arr2 = null;
	static short[] arr3 = null;
	static char[] arr4 = null;
	static int[] arr5 = null;
	static float[] arr6 = null;
	static double[] arr7 = null;

	public static void main(String[] args) throws Exception {
//		printRuntime();
//		printRuntime();
		printRuntime();
		arr1 = new boolean[10000000];
		printRuntime();
		arr2 = new byte[10000000];
		printRuntime();
		arr3 = new short[10000000];
		printRuntime();
		arr4 = new char[10000000];
		printRuntime();
		arr5 = new int[10000000];
		printRuntime();
		arr6 = new float[10000000];
		printRuntime();
		arr7 = new double[10000000];
		printRuntime();
//		Thread.sleep(100000);
	}
	
	private static void printRuntime() throws Exception {
        Runtime r = Runtime.getRuntime();
        System.out.println("JVM已使用内存:    " + (r.totalMemory() - r.freeMemory()));
//        System.out.println("JVM可以使用的总内存:    " + r.totalMemory());
//        System.out.println("JVM可以使用的剩余内存:    " + r.freeMemory());
	}
}
